<template>
  <div class="select-goods">
    <div class="search">
      <el-input type="text" v-model="queryParams.spuNo" placeholder="输入商品编号"/>
    </div>
    <el-table
      :data="goodsList"
      style="width: 100%"
      highlight-current-row
      @current-change="handleSelect"
    >
      <el-table-column
        prop="serialNo"
        label="商品编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="商品名称"
        width="200"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="queryParams.curPage"
      :page-sizes="[5]"
      :page-size="queryParams.pagesSize"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'select-goods',
  data() {
    return {
      goodsList: [],
      selectGood: null,
      queryParams: {
        spuNo: null,
        page: 0,
        limit: 5
      },
      total: 0,
    }
  },
  watch: {
    queryParams: {
      handler() {
        this.queryGoodsList()
      },
      deep: true
    }
  },
  mounted() {
    this.queryGoodsList()
  },
  methods: {
    handleSelect(row) {
      this.selectGood = row
    },
    queryGoodsList() {
      this.$http({
        url: this.$http.adornUrl('/mall/spuinfo/list'),
        method: 'post',
        params: this.$http.adornParams(this.queryParams),
      }).then(({data}) => {
        if (data.code !== 0) {
          this.$message.error('失败！')
        } else {
          this.goodsList = data.page.list
          this.total = data.page.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.queryParams.limit = val
    },
    // 当前页
    currentChangeHandle(val) {
      this.queryParams.page = val
    },
    doSure() {
      if (!this.selectGood) {
        this.$message.warning('请选择一条商品信息！')
      }
      return this.selectGood
    }
  }
}
</script>

<style scoped>

</style>
